<?php
declare(strict_types=1);

namespace Modules\Production\Http\Controllers;

use Catch\Base\CatchController as Controller;
use Modules\Production\Models\ProductionOrderDetail;
use Illuminate\Http\Request;
use Modules\Production\Repository\StockTaskScanRepository;


class ProductionOrderDetailController extends Controller
{
    public function __construct(
        protected readonly ProductionOrderDetail $model
    ){}

    /**
     * @param Request $request
     * @return mixed
     */
    public function index(): mixed
    {

        $list = $this->model->getList()->toArray();

        foreach ($list['data'] as &$val){
            //print_r($val['id']);exit();
            $val['scan_count'] = StockTaskScanRepository::getScanCountByProductionAndMaterial($val['production_order_id'],$val['fmaterialid1']);
        }

        return $list;
    }

    /**
     * @param Request $request
     * @return mixed
     */
    public function store(Request $request)
    {
        return $this->model->storeBy($request->all());
    }

    /**
     * @param $id
     * @return mixed
     */
    public function show($id)
    {
        return $this->model->firstBy($id);
    }

    /**
     * @param Request $request
     * @param $id
     * @return mixed
     */
    public function update($id, Request $request)
    {
        return $this->model->updateBy($id, $request->all());
    }

    /**
     * @param $id
     * @return mixed
     */
    public function destroy($id)
    {
        return $this->model->deleteBy($id);
    }

}
